import { BaseWindow } from "../../../component/window/BaseWindow";
import { Language } from "../../../../extend/language/Language";
import { ObjCreate } from "../common/ObjCreate";
import { GTextFormat } from "../../../common/GTextFormat";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { PulseSharedObject } from "./PulseSharedObject";
import { DataEvent } from "../../events/DataEvent";
import { GCheckBox } from "../../../../com/mui/controls/GCheckBox";
import { GButton } from "../../../../com/mui/controls/GButton";
//class TipsWindow
    
    export  class TipsWindow extends BaseWindow
    {
        constructor()
        {
            super();
            if (TipsWindow._instance != null) 
            {
                throw new Error("tipsWindow");
            }
            setSize(300, 180);
            title = Language.getString(30149);
            titleHeight = 30;
            return;
        }

        protected /* override */ createChildren(): void
        {
            super.createChildren();
            ObjCreate.createBg(17, 42, 265, 130, this);
            this._textfield = ObjCreate.createTextField("", 20, 55, 260, 80, this, new GTextFormat("", 12, 16777215, null, null, null, null, null, flash.text.TextFormatAlign.CENTER));
            this._textfield.wordWrap = true;
            this._textfield.multiline = true;
            this._sureBtn = ObjCreate.createGButton(Language.getString(30151), 85, 110, 50, 25, this);
            this._sureBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onSureBtnClickHandler);
            this._cancelBtn = ObjCreate.createGButton(Language.getString(30152), 165, 110, 50, 25, this);
            this._cancelBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onCancelBtnClickHandler);
            this._notTipCb = ObjCreate.createCheckBox(Language.getString(30150), 50, 145, 100, 20, this);
            this._notTipCb.addEventListener(flash.events.Event.CHANGE, this.onNotTipCbChangeHandler);
            return;
        }

        public createImgAndName(arg1: string, arg2: string): void
        {
            if (this.bitmap != null) 
            {
                addChild(this.bitmap);
                this.bitmap.bitmapData = GlobalClass.getBitmapData(arg1);
            }
            else 
            {
                this.bitmap = ObjCreate.createBitmap(arg1, this._notTipCb.x + this._notTipCb.width, this._notTipCb.y + 2, this);
            }
            if (this.text != null) 
            {
                addChild(this.text);
                this.text.text = arg2;
            }
            else 
            {
                this.text = ObjCreate.createTextField(arg2, this.bitmap.x + this.bitmap.width + 5, this._notTipCb.y, 60, 20, this, new GTextFormat("", 12, 16777215));
            }
            return;
        }

        /* internal  */onNotTipCbChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            if (this._notTipCb.selected != true) 
            {
                PulseSharedObject.saveValue(this._notTipsKey, false);
            }
            else 
            {
                PulseSharedObject.save(this._notTipsKey, true);
            }
            return;
        }

        /* internal  */onSureBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._eventName == "") 
            {
                if (this._eventFunction != null) 
                {
                    this._eventFunction();
                }
            }
            else 
            {
                dispatchEvent(new DataEvent(this._eventName));
                this._eventName = "";
            }
            this.hide();
            this.disposeImg();
            return;
        }

        /* internal  */onCancelBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this.hide();
            return;
        }

        public updateInfo(arg1: string, arg2: string, arg3: string="", arg4: Function=null): void
        {
            this.disposeImg();
            this._textfield.htmlText = arg1;
            this._notTipsKey = arg2;
            this._eventName = arg3;
            this._eventFunction = arg4;
            return;
        }

        /* internal  */disposeImg(): void
        {
            if (this.bitmap && this.bitmap.parent) 
            {
                removeChild(this.bitmap);
                this.bitmap.bitmapData = null;
            }
            if (this.text && this.text.parent) 
            {
                removeChild(this.text);
                this.text.text = "";
            }
            this._notTipCb.selected = false;
            return;
        }

        public setNotTipsVisible(arg1: Boolean): void
        {
            this._notTipCb.visible = arg1;
            return;
        }

        public /* override */ hide(): void
        {
            super.hide();
            this._eventName = "";
            this._eventFunction = null;
            this.disposeImg();
            return;
        }

        public static get instance(): TipsWindow
        {
            if (TipsWindow._instance == null) 
            {
                TipsWindow._instance = new TipsWindow();
            }
            return TipsWindow._instance;
        }

        /* internal */ /* var */_textfield: Object /* flash.text.TextField */;

        /* internal */ /* var */_notTipCb: GCheckBox;

        /* internal */ /* var */_sureBtn: GButton;

        /* internal */ /* var */_cancelBtn: GButton;

        /* internal */ /* var */_notTipsKey: string;

        /* internal */ /* var */_eventName: string="";

        /* internal */ /* var */_eventFunction: Function=null;

        protected /* var */bitmap: Object /* flash.display.Bitmap */;

        protected /* var */text: Object /* flash.text.TextField */;

        /* internal */ static /* var */_instance: TipsWindow;
    }
